package logic

import (
	"context"
	"hm-zero-mall/apps/address/models"

	"hm-zero-mall/apps/address/pb"
	"hm-zero-mall/apps/address/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateAddressLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateAddressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAddressLogic {
	return &UpdateAddressLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UpdateAddress 更新地址
func (l *UpdateAddressLogic) UpdateAddress(in *pb.AddressInfo) (*pb.Empty, error) {
	err := l.svcCtx.AddressModel.Update(l.ctx, &models.Address{
		Id:        in.Id,
		UserId:    in.Uid,
		Province:  in.Province,
		City:      in.City,
		Town:      in.Town,
		Street:    in.Street,
		Mobile:    in.Mobile,
		Contact:   in.Contact,
		Notes:     in.Notes,
		IsDefault: in.IsDefault,
	})
	return &pb.Empty{}, err
}
